<?php

class QuoteController extends BaseController {

  private $_url = 'http://feeds.feedburner.com/quotationspage/qotd';

  public function getQuotes() {

    $context = stream_context_create(array('http' => array('method' => 'GET')));
    $result  = file_get_contents($this->_url, false, $context);


    $channel = Zend\Feed\Reader\Reader::importString($result);
    $found   = 0;
    foreach ($channel as $item) {
      $author = trim($item->getTitle());
      $text   = $item->getDescription();
      $count  = Quote::where('author', '=', $author)->where('quote', '=', $text)->count();
      if ($count === 0) {
        $quote         = new Quote;
        $quote->author = $author;
        $quote->quote  = $text;
        $quote->save();
        $found++;
      }
    }
    return 'Found ' . $found . ' quotes.';
  }

}